<?php

class admin_controller_user_access extends controller
{
    
	// 登陆页面
	public function login()
	{
		$my = bone::get_admin();
		if($my->id>0)
		{
			$this->redirect('./?action=user.manager.dashboard');
			exit;
		}

		$template = $this->get_admin_template();
		$template->set_title('登陆');

		$template->display();
	}

	// 登陆检查
	public function ajax_login_check()
	{
		$username = post('username');
		$password = post('password');

		if(!$username || !$password)
		{
			$this->set_ajax('status', 1);
			$this->set_ajax('description', '用户名或密码不能为空');
			$this->ajax();
		}

		$model = $this->get_admin_model();
		$user = $model->login($username, $password );
		
		if( $user )
		{
		    system_log('登陆后台');
		    
			$this->set_ajax('status', 0);
			$this->set_ajax('description', '登陆成功');
			$this->ajax();
		}
		else
		{
			$this->set_ajax('status', 2);
			$this->set_ajax('description', $model->get_error() );
			$this->ajax();
		}
	}


	// 退出登陆
	public function logout()
	{
		$model = $this->get_admin_model();
		$model->logout();

		$this->redirect('./?action=user.access.login', '成功退出');
	}
    
}

?>